import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import '../extension/index.dart';
import 'index.dart';

///顶部的操作按钮
class CommonRootAction extends StatelessWidget {
  const CommonRootAction({
    Key? key,
    required this.onTap,
    this.img,
    this.child,
    this.backColor = Colors.black,
    this.size,
    this.rightPadding,
    this.contentPadding,
  }) : super(key: key);

  final String? img;
  final Widget? child;
  final Function() onTap;
  final Color? backColor;
  final double? size;
  final double? rightPadding;
  final EdgeInsets? contentPadding;

  @override
  Widget build(BuildContext context) {
    Widget widget = Container();
    if (img.notEmpty) {
      widget = SvgPicture.asset(
        img!,
        width: size ?? 22.w,
        height: size ?? 22.w,
        color: backColor,
      );
    } else if (child != null) {
      widget = child!;
    }

    return UnconstrainedBox(
      child: Padding(
        padding: EdgeInsets.only(right: rightPadding ?? 10.w),
        child: ButtonWidget.icon(
          widget,
          onTap: onTap,
          padding: contentPadding ?? EdgeInsets.all(5.w),
          hasInkWell: false,
        ),
      ),
    );
  }
}
